<?php
/* SVN FILE: $Id: players_controller.php 285 2010-06-27 18:41:50Z gregory.rome $ */
/**
 * Players Controller.
 *
 * Players teams.
 *
 * cBBweb : Digital Blood Bowl league interface (http://code.google.com/p/cbbweb/)
 * Copyright 2009-2010, Grégory Romé.
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2009-2010, Grégory Romé.
 * @link          http://code.google.com/p/cbbweb/ cBBweb Project
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 * @version       $Revision: 285 $
 * @modifiedby    $LastChangedBy: gregory.rome $
 * @lastmodified  $Date: 2010-06-27 18:41:50 +0000 (Sun, 27 Jun 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Players Controller.
 *
 * @package       cbbweb
 * @subpackage    cbbweb.controllers
 */
class PlayersController extends AppController {

	var $name = 'Players';
	var $paginate = array(
    	'Player' => array(
    		'order' => array('Player.idTeam_Listing'),
	    	'contain' => array(
				'Team' => array(
					'fields' => array('Team.ID', 'Team.strName'),
				),
				'Race' => array(
					'LocalizedString'
				),
	    		'Skill' => array(
						'LocalizedString',
						'FormattedString'
	  			),
	    		'PlayerType' => array(
	    			'LocalizedString',
	    				'Skill' => array(
								'LocalizedString',
								'FormattedString'
								)
								),
	    		'PlayerLevel' => array(
	    			'LocalizedString')
    )));

    function index() {
    	$this->set('players', $this->paginate('Player'));
    }

    function view($id = null) {
    	if (!$id) {
    		$this->Session->setFlash(__('Invalid Player.', true));
    		$this->redirect(array('action'=>'index'));
    	}
    	$this->Player->recursive = 2;
    	$player = $this->Player->read(null, $id);
    	if (isset($this->params['requested'])) {
    		return $player;
    	} else {
    		$this->set('player', $player);
    	}
    }


    function delete($id = null) {
    	if (!$id) {
    		$this->Session->setFlash(__('Invalid id for Player', true));
    		$this->redirect(array('action'=>'index'));
    	}
    	if ($this->Player->delete($id)) {
    		$this->Session->setFlash(__('Player deleted', true));
    		$this->redirect(array('action'=>'index'));
    	}
    }

}
?>
